package com.huishu.user.controller;


import com.huishu.commons.pojo.Result;
import com.huishu.user.pojo.dto.UserReceiveAddressDTO;
import com.huishu.user.service.UserReceiveAddressService;
import com.huishu.user.utils.AssistantContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @author generator@ljj
* @since 2023-04-12
*/
@RestController
@RequestMapping("/user-receive-address")
@Slf4j
public class UserReceiveAddressController {

    @Autowired
    private UserReceiveAddressService userReceiveAddressService;

    @PostMapping("/add")
    public Result add(@RequestBody UserReceiveAddressDTO userReceiveAddressDTO){
        return userReceiveAddressService.addOrUpdate(userReceiveAddressDTO);
    }

    @PostMapping("/update")
    public Result modify(@RequestBody UserReceiveAddressDTO userReceiveAddressDTO){
        return userReceiveAddressService.addOrUpdate(userReceiveAddressDTO);
    }

    @GetMapping("/find-all")
    public Result findAll(){
        return userReceiveAddressService.findAll(AssistantContext.getCurrentUid());
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        userReceiveAddressService.removeById(id);
        return Result.success();
    }

    @GetMapping("/find-default")
    public Result findDefault(){
        return userReceiveAddressService.findDefault(AssistantContext.getCurrentUid());
    }
}
